<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <title>Examples</title>
    <meta name="description" content="">
    <meta name="keywords" content="">
    <link href="" rel="stylesheet">
    <script src="lib/vue.js"></script>
</head>

<body>
    <div id="app">
        单价：<input type="text" v-model="price"><br>
        数量：<input type="text" v-model="number"><br>
        方法总价：{{ getAmount() }} <br>
        计算总价：{{ computedAmount }} <br>
        监听总价：{{ amount }} <br>

        客户身份：{{ status }}
    </div>

    <script>
        new Vue({
            el: "#app",
            data: {
                price: 100,
                number: 0,
                amount: 0,
                status: "普通消费者"
            },
            methods: {
                getAmount() {
                    console.log("getAmount()");
                    return this.price * this.number
                }
            },
            computed: {
                computedAmount() {
                    console.log("computedAmount()");
                    return this.price * this.number
                }
            },
            watch: {
                price() {
                    console.log("price发生了变化");
                    this.amount = this.price * this.number
                    if (this.price > 1000) {
                        this.status = "VIP用户"
                    }
                },
                number() {
                    console.log("number发生了变化");
                    this.amount = this.price * this.number
                    if (this.number > 10) {
                        this.status = "购物狂"
                    }
                }
            }
        })
    </script>
</body>

</html>